from odoo import fields


class FlowLogFunctions(object):
    """
   Model:
        满足所有流水相关的算法逻辑
   Params:
        -env:odoo env
    """

    def __init__(self, env):
        self.env = env

    def save_flow_log(self, operation_person=None, rp_customer_id=None, category_id=None, related_record=None,
                      change_type=None, funds_change=None, rp_flow_record_log_line_ids=None):
        """
        创建流水
        Params:
            -operation_person:操作人
            -rp_customer_id:客户
            -category_id:一级分类
            -related_record:关联记录
            -change_type:变化类型
            -funds_change:价格变动
            -rp_flow_record_log_line_ids:流水详情
        """
        datas = []
        data = {
            'operation_person': operation_person if operation_person else False,
            'rp_customer_id': rp_customer_id if rp_customer_id else False,
            'category_id': category_id if category_id else False,
            'related_record': related_record if related_record else False,
            'change_type': change_type if change_type else False,
            'funds_change': funds_change if funds_change else False,
            'rp_flow_record_log_line_ids': rp_flow_record_log_line_ids if rp_flow_record_log_line_ids else False,
            'date_create': fields.Datetime.now()
        }
        datas.append(data)
        self.env['rp.flow.log'].create(datas)
